package com.learning.springboot.email;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import javax.annotation.Resource;

/**
 * @Date 2023/8/28 21:13
 * @Author 李荣浩
 * @Description
 */
@EnableScheduling
@SpringBootApplication
public class SpringbootEmailApplication {

    @Resource
    private JavaMailSender sender;

    @Scheduled(cron = "0 */1 * * * ?")
    public void sendEmail() {
        String email = "956236650@qq.com";
        SimpleMailMessage message = new SimpleMailMessage();
        message.setSubject("来自老公的消息");
        message.setText("爱老婆爱生活爱宝宝佳佳");
        message.setTo(email);
        message.setFrom("1871446702@qq.com");
        sender.send(message);
        System.out.println("邮件已发送");
    }

    public static void main(String[] args) {
        SpringApplication.run(SpringbootEmailApplication.class);
    }
}
